import processing.core.*; 
import processing.xml.*; 

import ijeoma.tween.*; 
import ijeoma.easing.*; 
import processing.core.PApplet; 
import processing.core.PVector; 

import java.applet.*; 
import java.awt.*; 
import java.awt.image.*; 
import java.awt.event.*; 
import java.io.*; 
import java.net.*; 
import java.text.*; 
import java.util.*; 
import java.util.zip.*; 
import java.util.regex.*; 

public class RectObjectTweenExample extends PApplet {




static int FPS = 32;

Rect rect;
Tween tween1, tween2, tween3, tween4;
TweenGroup tweenGroup;

public void setup() {
    size(400, 400, P3D);

  frameRate(FPS);
  rectMode(CENTER);

  rect = new Rect(this, width/2, height/2, width, height, color(0));

  float duration = 100f;

  tween1 = new Tween(this, "Tween1", rect, "scaleX", 0f, 1f, duration, Tween.FRAMES, 0f, new Quad(), Tween.EASE_IN);
  tween2 = new Tween(this, "Tween2", rect, "scaleY", 1f, 0f, duration, Tween.FRAMES, 0f, new Quad(), Tween.EASE_IN);
  tween3 = new Tween(this, "Tween3", rect, "scaleX", 1f, 0f, duration, Tween.FRAMES, 0f, new Quad(), Tween.EASE_IN);
  tween4 = new Tween(this, "Tween4", rect, "scaleY", 0f, 1f, duration, Tween.FRAMES, 0f, new Quad(), Tween.EASE_IN);

  tweenGroup = new TweenGroup(this, new Object[]{tween1, tween2, tween3, tween4});
  tweenGroup.repeat(Tween.REVERSE);
  tweenGroup.start();
}

public void draw() {
  background(255);

  tweenGroup.update();
  
  rect.draw();
}

public void tweenStartedEvent(TweenEvent te) {
  println(te);
}

public void tweenEndedEvent(TweenEvent te) {
  println(te);
}

public void tweenGroupStartedEvent(TweenEvent te) {
  println(te);
}

public void tweenGroupEndedEvent(TweenEvent te) {
  println(te);
}








public class Rect {
  public PApplet parent;

  public PVector position = new PVector(0, 0, 0);

  public float width = 0;
  public float height = 0;

  public float scaleX = 100;
  public float scaleY = 100;

  public float rotation = 0;

  public float alpha = 255;
  int colour = 0;

  public Rect(PApplet _parent, float _x, float _y, float _width, float _height, int _color) {
    parent = _parent;
    position = new PVector(_x,_y,0);
    width = _width;
    height = _height;
    colour = _color;
    rotation = 0;
  }

  public Rect(PApplet _parent, int _x, int _y, int _width, int _height, int _color) {
    parent = _parent;
    position = new PVector(_x,_y,0);
    width = (float)_width;
    height = (float)_height;
    colour = _color;
    rotation = 0;
  }


  public void draw() {
    parent.pushMatrix();
    parent.translate(position.x, position.y, position.z);
    parent.scale(scaleX, scaleY);
    parent.rotate(rotation);
    parent.noStroke();
    parent.fill(colour, alpha);
    parent.rect(0, 0, width, height);
    parent.popMatrix();
  }
}




  static public void main(String args[]) {
    PApplet.main(new String[] { "--bgcolor=#FFFFFF", "RectObjectTweenExample" });
  }
}
